<?php
	header('Content-type: image/jpeg');
	
	//chieu rong, chieu cao cua hinh
	$width = 50;
	$height = 24;
	
	//thiet lap mot hinh voi chieu rong va chieu cao o tren 
	$my_image = imagecreatetruecolor($width, $height);
	
	//to nen trang cho hinh
	imagefill($my_image, 0, 0, 0xFFFFFF);
	
	//them cac cham mau do vao trong hinh voi toa do x,y ngau nhien
	for ($c = 0; $c < 40; $c++)
	{
		$x = rand(0,$width-1);
		$y = rand(0,$height-1);
		imagesetpixel($my_image, $x, $y, 0xFF0000);
	}
 
	//tao mot chuoi ngau nhien
	$rand_string = md5(rand(1000,9999));
	
	//tao mot mau ngau nhien
	$rand_color = rand(0x000000, 0xFFFFFF);
	
	//gan chuoi, mau ngau nhien vao tam hinh voi toa do font=5, x=5, y=5
	imagestring($my_image, 5, 5, 5, $rand_string, $rand_color);
	
	//tao cookie
	setcookie('chiasekinhnghiem',$rand_string);
	
	//xuat hinh anh da tao
	imagejpeg($my_image);
	imagedestroy($my_image); 
 ?>